package com.gu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gu.VO.ServerResponse;
import com.gu.dao.SettingDAO;
import com.gu.entity.Setting;
import com.gu.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: gusongliao
 * @Description:
 * @createDate 2023/01/05 22:02
 */
@Service
public class SettingServiceImpl implements SettingService {

    @Autowired
    private SettingDAO settingDAO;

    @Override
    public Setting selectSettingByModuleAndName(String module, String name) {
        return settingDAO.selectSettingByModuleAndName(module, name);
    }

    @Override
    public PageInfo settingList(Integer pageNum, Integer pageSize, String module, String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<Setting> settingList = settingDAO.getAllSetting();
        PageInfo pageInfo = PageInfo.of(settingList);
        return pageInfo;
    }

    @Override
    public ServerResponse updateSetting(Setting setting) {
        int i = settingDAO.updateByPrimaryKey(setting);
        if (i == 0) {
            return ServerResponse.error(500, "更新失败");
        } else {
            return ServerResponse.SUCCESS;
        }
    }
}
